﻿<cfscript>
/** 
* ORM ClassroomBorrow
* 
* @hint "Hibernate persistenter t_clsroom_borrow. 临时性教室借用申请" 
* 
*/ 

component 
	displayname="public.service.orm.senate.ClassroomBorrow" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="ClassroomBorrow" 
	table="t_clsroom_borrow"
	{
	
	property type="string" name="BorrowID" column="cbr_id" fieldtype="id" generator="assigned" hint="教室使用申请单号";

	property type="string" name="TimeSign" column="time_sign" hint="申请时间";
	property type="string" name="TimeReview" column="time_review" hint="批复时间";
	property type="string" name="Reviewer" column="tch_approve" hint="审批人";
	property type="string" name="BorrowWeek" column="use_week" hint="借用周次";
	property type="string" name="BorrowTime" column="use_time" hint="借用时间";
	property type="string" name="Classrooms" column="use_rooms" hint="教室ID列表";
	property type="string" name="SignStat" column="proc_stat" hint="申请单据状态";

	property name="Teacher" fieldtype="many-to-one" fkcolumn="tch_id" cfc="Teacher"  hint="申请教师";
	property name="Institute" fieldtype="many-to-one" fkcolumn="institute_id" cfc="Institute"  hint="借用单位";
	property name="Usage" fieldtype="many-to-one" fkcolumn="ut_id" cfc="ClassroomUseType"  hint="教室占用类别";
	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term"  hint="学期";

	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = DateFormat(now(), "YYYYMMDD") & numberFormat(1, "0_____");
		var checkArray = ORMExecuteQuery("select BorrowID from ClassroomBorrow 
											where BorrowID like :condition
											order by BorrowID desc", { condition=DateFormat(now(), "YYYYMMDD") & "______" }, { maxResults=1 });
		/* 
			主键生成规则 CHAR(14)
			
			8位日期 6位为流水号
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = DateFormat(now(), "YYYYMMDD") & numberFormat((right(checkArray[1], 6) + 1), "0_____");			
		}

		return nextID;
	}

}

</cfscript>